import tensorflow as tf
from tensorflow.keras import layers

# 全连接层
# x = tf.random.normal([2, 784])
# w1 = tf.Variable(tf.random.truncated_normal([784, 256], stddev=0.1))
# b1 = tf.Variable(tf.zeros([256]))
# o1 = tf.matmul(x, w1) + b1
# o1 = tf.nn.relu(o1)
# print(o1)


x = tf.random.normal([4, 28*28])
# 创建全连接层，指定输出节点数和激活函数
fc = layers.Dense(512, activation=tf.nn.relu)
# 通过fc类实例完成一次全连接层的计算，返回输出张量
h1 = fc(x)
print(h1)
w = fc.kernel # 根据输出节点数，计算w的shape
b = fc.bias   # 根据输出节点数，计算b的shape
print(w, b)
print(fc.trainable_variables)
